﻿using System;
using System.Collections.Generic;
using System.Linq;
using Common.Extension;
using Common.Model;
using Common.util;
using Dapper;
using Spider.Mode;

namespace Common.Dao
{
    public class DxwBlockDao
    {
        //保存板块
        public static void BatchSaveDxwBlock(List<DxwBlock> blocks)
        {
            String sql =
                @"insert ignore dxw_block(block_name,topic_name)  " +
                "values (@BlockCode,@BlockName,@TopicName)";
            using (var conn = DbUtils.GetHotTopicConnection())
            {
                conn.InsertMultiple(sql, blocks);
            }
        }

        //保存板块
        public static void UpdateDxwBlockTopicName(List<DxwBlock> blocks)
        {
            String sql =
                @"update dxw_block set topic_name = @TopicName where id = @id";
            using (var conn = DbUtils.GetHotTopicConnection())
            {
                conn.InsertMultiple(sql, blocks);
            }
        }

        //获取板块
        public static List<DxwBlock> GetDxwBlock()
        {
            String sql =
                "select block_name as BlockName,topic_name as TopicName,id from `dxw_block` where is_deleted = 0";

            using (var conn = DbUtils.GetHotTopicConnection())
            {
                IEnumerable<DxwBlock> list = conn.Query<DxwBlock>(sql);
                if (list != null && list.Any())
                {
                    return list.ToList();
                }
                else
                {
                    return null;
                }
            }
        }
    }
}